?><?
class cls_clipboard extends cls_entity{
  function search($id){
    for($i=0;$i<count($this->items);$i++){
      if($this->items[$i][0]==$id)return $i;
    }
    return false;
  }
  
  function add($id,$method=cbCopy){
     if($this->search($id)===false){
       $this->items[]=array($id,$method);
       $this->save();
     }
  }
  
  function remove($id){
     if(!$id)return false;
     if($this->search($id)!==false){
       unset($this->items[$this->search($id)]);
       $this->save();
     }
  }

  function save(){
     $_SESSION["clipboard"]=$this->items;
  }
  
  function load(){
     if(isset($_SESSION["clipboard"])){
       $this->items=$_SESSION["clipboard"];
     }else{
       $this->items=array();
     }   
  }
  function clear(){
    $this->items=array();
    $this->save();
  }

  function accept_content($container){
    $classes=&get_entity("cls_classes");
    $result=true;
    while($item=&$this->inext()){
      $object=&object_by_id($item[0]);
      if(!$object->parent||!$classes->is_accept($container,$object)){
        $result=false;
      }  
    }
    if(count($this->items)==0){
      return false;
    }else{
      return $result;
    }
  }
}